import 'dart:io';
import 'dart:ui';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:package_info_plus/package_info_plus.dart';

class XmmPlatformUtils {
  ///预初始化，不涉及权限和隐私相关的，可以在隐私政策前调用初始化
  static preInit() async {
    _packageInfo = await PackageInfo.fromPlatform();
  }

  static PackageInfo? _packageInfo;

  static PackageInfo? get packageInfo => _packageInfo;

  static String get appVersionName => _packageInfo?.version ?? "1.0.0";

  static String get appVersionCode => _packageInfo?.buildNumber ?? "1";

  static String get appName => _packageInfo?.appName ?? "";

  static String get packageName => _packageInfo?.packageName ?? "";

  ///初始化，涉及到和隐私相关的
  static init() async {
    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
    if (Platform.isAndroid) {
      androidInfo = await deviceInfo.androidInfo;
      deviceId = androidInfo?.id;
    } else if (Platform.isIOS) {
      iosInfo = await deviceInfo.iosInfo;
      deviceId = iosInfo?.identifierForVendor;
    }
  }

  static AndroidDeviceInfo? androidInfo;

  static IosDeviceInfo? iosInfo;

  static String? deviceId;

  static String get model {
    if (Platform.isAndroid) {
      return androidInfo?.hardware ?? "";
    } else if (Platform.isIOS) {
      return iosInfo?.model ?? "";
    }
    return "";
  }

  static String get systemLanguage => window.locale.languageCode;
}
